<template>
	<view class="container">
		<view class="sticky">
			<view><text class="mr100" @tap="navgetTo('pages/my/receipt_order','','')">收款订单</text><text class="active" @tap="navgetTo('pages/my/expand_order','','')">支出订单</text></view>
			<view class="is-flex p010">
				<view class="is-flex">
					<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
						<view class="uni-input">{{date}}</view>
					</picker>
					<uni-icons type="down" size="20" color="#666"></uni-icons>
				</view>
				<view class="flex1">
					<uni-search-bar v-model="keyword" radius="5" placeholder="输入手机号、线路、行程查询" clearButton="auto" cancelButton="none" />
				</view>
				<view class="mt20">
					<button class="mini-btn p010" type="default" style="backgroundColor:#397bff;color:#fff;" size="mini" @confirm="getPageList('onPullDownRefresh')">查询</button>
				</view>
			</view>
		</view>
		<scroll-view scroll-y="true" scroll-x="false" :style="{height:scrollH+'px'}" refresher-enabled="true" :refresher-triggered="isRefreshing" @refresherrefresh="onRefresh" @scrolltolower="onLoadMore">
		<view class="pb130" v-if="List.length>0">
			<view class="p3020" v-for="item in List" @tap="navgetTo('pages/my/order_detail',item.orderNo,'')">
				<view class="uni-flex mb25">
					<view class="color-black">
						{{item.createDate}}
					</view>
					<view class="color-red" v-if="item.orderStatus == 1">待支付</view>
					<view class="color-red" v-if="item.orderStatus == 2">支付中</view>
					<view class="color-red" v-if="item.orderStatus == 3">支付成功</view>
					<view class="color-red" v-if="item.orderStatus == 4">已完结</view>
					<view class="color-red" v-if="item.orderStatus == 9">退款中</view>
					<view class="color-red" v-if="item.orderStatus == -1">已取消</view>
				</view>
				<view class="card-list is-flex">
					<image :src="item.coverUrl"></image>
					<view class="card-item">
						<view class="color-black mb25">行程：{{item.itineraryTitle}}</view>
						<view>路线：{{item.linesTitle}}</view>
						<view class="uni-flex">
							<view class="">
								<text>用户：{{item.nickName}}</text> 
							</view>
							<view class="">
								<text>总计：</text>
								<text class="color-red">￥{{item.orderAmount}}</text> 
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 加载提示 -->
		<view v-if="isLoading" class="mt100 mb100">{{loadMoreText}}</view>
		</scroll-view>
	</view>
</template>

<script>
	import api from '@/common/api/webapi.js'; /*api*/
	export default {
		components: {
			
		},
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				bannerList: [{
					url: "../../static/xcimg.png"
				}, {
					url: "../../static/xcimg.png"
				}, {
					url: "../../static/xcimg.png"
				}],
				starValue:0,
				maxStar:5,
				single: "",
				keyword:'',
				date: '全部时间',
				start: Date.now(),
				end: Date.now() + 180*24*3600*1000,
				region: '香格里拉',
				citys: '[{ "name": "北京市", "cityList": [ { "name": "北京市", "districtList": ["东城区", "西城区"] } ]',
				customItem: '',
				scrollH:0,
				isRefreshing:false,
				isLoading:false,
				loadMoreText:"加载中...",
				List:[],
				param: {
					page: 1, //当前页
					limit: 10, //每页显示记录数
					PageCount: 0,
				},
			}
		},
		onReady() {
			// 获取可滚动区域的高度：视口高度 - tabbar切换卡高度就是剩余的内容可滚动的。
			//如果你使用取消了原生导航栏，记着把你自定义导航栏的高度也减掉哦
			uni.getSystemInfo({
				success: (res) => {
					this.scrollH = res.windowHeight - uni.upx2px(100)
				}
			})
		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		watch: {

		},
		onShow() {
		},
		onLoad(option) {
			this.getPageList('onPullDownRefresh');
		},
		mounted(){
		},
		methods: {
			checkIsLogin() {
				// let userLoginFlag = storageUtil.getStorageData("isLogin");

				// if (!userLoginFlag || userLoginFlag == '') {
				// 	this.popShowHandle();
				// 	return;
				// }
			},
			dateChange: function(e) {
				this.date = e.detail.value;
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				if (type === 'start') {
					year = year;
				} else if (type === 'end') {
					if (month > 6) {
						year = year + 1;
					}
					year = year;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			// 城市选择器
			bindRegionChange: function(e) {
				this.region = e.detail.value;
			},
			// 星级点击事件
			starChange:function(e){
				this.starValue+1;
			},
			// 页面跳转
			navgetTo(page, param, type) {
				if (param != undefined) {
					type = type || '';
					let data = {
						data: param,
						page: type
					}
					uni.navigateTo({
						url: "/" + page + "?param=" + encodeURI(JSON.stringify(data))
					});
				} else {
					uni.navigateTo({
						url: "/" + page
					});
				}
			},
			onRefresh() {  // 下拉刷新
				this.isRefreshing = true;
				this.param.page = 1;
				this.getPageList('onPullDownRefresh');
			},
			onLoadMore() {  // 上拉加载
				if (this.isLoading) return;
				this.isLoading = true;
				this.param.page = (this.param.page + 1);
				if (this.param.page > this.param.PageCount) {
					this.isLoading = true;
					this.loadMoreText = "--到底啦--"
					return;
				}
				this.getPageList('onReachBottom');
			},
			// 获取分页列表
			getPageList(type) {
				let _this = this;
			
				let requestData = {
					params: {
						pageType:'PAY',
						keyword:_this.param.keyword,//搜索关键字
						page: _this.param.page, //当前页
						size: _this.param.limit, //每页显示记录数
						startDate:_this.param.startDate,
						endDate:_this.param.endDate
					}
				}
			
				api.getOrderList(requestData).then(res => {
					if (res.code === 0) {
						if (res.data.length > 0) {
							let pagelist = res.data;
							_this.param.PageCount = Math.ceil(res.data.total / _this.param.limit);
							if (type == "onReachBottom") {
								_this.List = _this.List.concat(pagelist)
							} else {
								_this.List = pagelist;
							}
						}else{
							if(type == "onPullDownRefresh"){
								_this.List = [];
							}else if(type == "onReachBottom"){
								this.loadMoreText = "--到底啦--"
							}
						}
					} else {}
				_this.isRefreshing = false;
				_this.loadMoreText = "";
				}).catch(function(){
					_this.isRefreshing = false;
					_this.loadMoreText = "";
				})
			
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		font-size: 14px;
		line-height: 24px;
	}

	.index-swiper {
		width: 100%;
		height: 670rpx;
	}

	.index-swiper image {
		width: 100%;
		height: 100%;
		object-fit: contain;
	}
	
	.bottom-wrap{
		position: relative;
		top: -60rpx;
	}
	
	.is-flex{
		display: flex;
		align-items: center;
	}
	.flex1{
		flex: 1;
	}
	.mini-btn.p010{
		padding: 0 10px;
	}
	::v-deep.uni-searchbar__text-placeholder {
	    font-size: 12px;
	}
	::v-deep.uni-searchbar__box-search-input {
	    text-align: left;
	}
	.xf-wrap {
		position: relative;
		top: -60rpx;
		overflow: hidden;
	}

	.box-shadow {
		box-shadow: 2rpx 2px 2rpx $uni-text-color-grey8;
		background-color: #ffffff;
		border-radius: 20rpx;
	}

	.xf-wrap input {
		font-weight: bold;
	}

	.uni-flex {
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
	}

	.uni-row {
		flex-direction: row;
	}
	.sticky {
		height: 200rpx;
		line-height: 85rpx;
		background-color: #ffffff;
		width: 100%;
		color: #888;
		position: sticky;
		top: -1rpx;
		left: 0;
		right: 0;
		z-index: 999;
		text-align: center;
	}

	.sticky text {
		color: $uni-text-color-light-blue;
		font-weight: bold;
		padding: 10rpx 15rpx;
	}
	.sticky text.active{
		color: $uni-text-color-blue;
		border-bottom: 2px solid $uni-text-color-blue;
	}
	.card-list{
		image{
			width: 170rpx;
			height: 170rpx;
		}
		.card-item{
			flex: 1;
			margin-left: 25rpx;
		}
	}
	.pb130{
		padding-bottom: calc( 130rpx + max(env(safe-area-inset-bottom),20px));
	}
	.share-reward{
		.color-black{
			display: block;
			margin-bottom: 20rpx;
		}
		.is-flex{
			align-items: flex-start;
		}
		.color-gray{
			line-height: 1.8;
			text-align: justify;
			margin-left: 20rpx;
		}
	}
	
</style>